<?php

/**
 * SimplifyPHP Framework
 *
 * This file is part of SimplifyPHP Framework.
 *
 * SimplifyPHP Framework is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * SimplifyPHP Framework is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Rodrigo Rutkoski Rodrigues, <rutkoski@gmail.com>
 */

/**
 * Abstract Action Controller
 *
 * @author Rodrigo Rutkoski Rodrigues <rutkoski@gmail.com>
 * @package Simplify_Kernel_Core
 */
abstract class AbstractActionController extends ActionControllerImpl
{

  /**
   * Default 404 action.
   *
   * @return void
   */
  protected function action_404()
  {
    $this->response->header('HTTP/1.1 404 Not Found');

    $tpl = $this->getTemplate();

    if (! file_exists($tpl)) {
      return false;
    }
  }

  /**
   * Default display action. Displays static actions.
   *
   * @return void
   */
  protected function action_display()
  {
    $parts = func_get_args();

    $path = $this->config->get('home_dir', '{app_dir}/home') . '/' . implode('/', $parts);
    $path .= is_dir($path) ? '/index_action.php' : '_action.php';

    if (! file_exists($path))
      return $this->callAction('404');

    $this->setTemplate($path);
  }

  /**
   * Default index action.
   *
   * @return void
   */
  protected function action_index()
  {
  }

  protected function action_gateway()
  {
    require_once (SY_DIR . '/lib/amf/core/amf/app/Gateway.php');

    $gateway = new Gateway();

    $gateway->setClassPath($this->config->get('app_dir') . '/model/services/');
    $gateway->setClassMappingsPath($this->config->get('app_dir') . '/model/services/vo/');
    $gateway->setCharsetHandler("none", "ISO-8859-1", "ISO-8859-1");
    $gateway->setErrorHandling(E_ALL ^ (E_NOTICE | E_DEPRECATED));

    if (SY_DEBUG_ENABLED !== true) {
      $gateway->disableDebug();
      $gateway->disableStandalonePlayer();
    }

    $gateway->enableGzipCompression(25 * 1024);
    $gateway->service();

    return false;
  }

}

?>